MESSAGE("+++++++++++++++++++++++++platform: " ${CMAKE_CL_64})

# IF(CMAKE_CL_64)
#     set(platform x64)
# ELSE(CMAKE_CL_64)
#     set(platform x86)
#     USE_32BITS
# ENDIF(CMAKE_CL_64)

# xenv环境初始化
MACRO(xenv_init)
	SET(XEVN_TAR_WIN TRUE) # 目标操作系统
	                       # 目标编译器
	SET(XENV_IS_X86 TRUE)  # 目标cpu
ENDMACRO()

xenv_init()
MESSAGE("xenv: " ${XENV_IS_X86}) 

# x_add_exe()
# x_add_dll()
# x_add_lib()
# x_add_define()
# x_add_defines()
# x_add_dependent_lib()
# x_add_dependent_libs()
# x_define_prebuild_lib()
# x_collect_files()

x_collect_files()

FUNCTION(x_add_dll dll_name sources)
#MACRO(x_add_dll dll_name sources)
    MESSAGE("[xcmake] x_add_dll: " ${dll_name})
    MESSAGE("[xcmake] " ${sources})
    ADD_LIBRARY(${dll_name} STATIC ${sources})
#ENDMACRO()
ENDFUNCTION()

set(src ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/asm/make_i386_ms_pe_masm.asm)
x_add_dll(test ${src})

#设置项目名
SET(project_name boost_cmake_context)

#MESSAGE(STATUS "add project: name=" ${project_name} ",type=" ${project_type} ",target_platform=" ${project_target_platform})

# 检查并开启MASM汇编器
ENABLE_LANGUAGE(ASM_MASM) 
IF(CMAKE_ASM_MASM_COMPILER_WORKS) 
    message("enable masm")
ENDIF() 

#文件 
SET(project_source_file_list
	${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/asm/make_i386_ms_pe_masm.asm
    ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/asm/jump_i386_ms_pe_masm.asm
    ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/asm/ontop_i386_ms_pe_masm.asm
    ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/dummy.cpp
	
	#
)

# win32 x86 asm文件
# win32 x64 asm文件

#win32专用文件
IF(project_target_platform STREQUAL "WIN32")
	SET(project_source_file_list 
		${project_source_file_list}
		${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/windows/stack_traits.cpp
		#${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/fiber.cpp
		#${CMAKE_CURRENT_SOURCE_DIR}/../../libs/context/src/continuation.cpp
	)
ENDIF()

ADD_DEFINITIONS(-D_WIN32_WINNT=0x0601)

#ADD_DEFINITIONS(-DBOOST_SYSTEM_STATIC_LINK)
#ADD_DEFINITIONS(-DBOOST_CONTEXT_EXPORT -DBOOST_CONTEXT_SOURCE -DBOOST_DISABLE_ASSERTS)
ADD_LIBRARY(boost_cmake_context_static STATIC ${project_source_file_list})
TARGET_LINK_OPTIONS(boost_cmake_context_static PRIVATE "/SAFESEH:NO")
SET_TARGET_PROPERTIES(boost_cmake_context_static PROPERTIES
    COMPILE_DEFINITIONS "BOOST_CONTEXT_EXPORT BOOST_CONTEXT_SOURCE")

#ADD_DEFINITIONS(-DBOOST_SYSTEM_DYN_LINK)
#ADD_DEFINITIONS(-DBOOST_CONTEXT_EXPORT=EXPORT -DBOOST_CONTEXT_SOURCE -DBOOST_CONTEXT_DYN_LINK=1 -DBOOST_DISABLE_ASSERTS)
ADD_LIBRARY(boost_cmake_context SHARED ${project_source_file_list})
TARGET_LINK_OPTIONS(boost_cmake_context PRIVATE "/SAFESEH:NO")
SET_TARGET_PROPERTIES(boost_cmake_context PROPERTIES
    COMPILE_DEFINITIONS "BOOST_CONTEXT_EXPORT=EXPORT=1 BOOST_CONTEXT_SOURCE")

#SET(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} /D \"SAFESEH:NO\"")
#SET(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
#SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
#SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")






